package com.jet.member.gate;

import com.jet.core.result.ResultJson;
import com.jet.member.domain.entity.MemberTimeCard;
import com.jet.member.domain.vo.MemberTimeCardListVo;
import com.jet.member.service.IMemberTimeCardService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/gate/member/time-card")
public class GateMemberTimeCardController {

    private final IMemberTimeCardService memberTimeCardService;

    public GateMemberTimeCardController(IMemberTimeCardService memberTimeCardService) {
        this.memberTimeCardService = memberTimeCardService;
    }

    /**
     * 获取当前商户、会员、商品可使用的计次卡信息
     *
     * @param merchantNo
     * @param storeNo
     * @param accountId
     * @param memberId
     * @return
     */
    @GetMapping("/list/spu-no/{memberId}")
    public ResultJson<List<MemberTimeCard>> listBySpuNo(@RequestHeader long merchantNo,
                                                        @RequestHeader long storeNo,
                                                        @RequestHeader String accountId,
                                                        @PathVariable("memberId") String memberId,
                                                        @RequestParam String spuId) {
        return ResultJson.ok(memberTimeCardService.findAllByMemberIdAndSpuId(memberId, spuId));
    }

    /**
     * 计次卡信息
     *
     * @param merchantNo
     * @param storeNo
     * @param accountId
     * @param memberId
     * @return
     */
    @GetMapping("/list/{memberId}")
    public ResultJson<List<MemberTimeCardListVo>> list(@RequestHeader long merchantNo,
                                                       @RequestHeader long storeNo,
                                                       @RequestHeader String accountId,
                                                       @PathVariable("memberId") String memberId) {
        return ResultJson.ok(memberTimeCardService.findAllByMemberId(memberId));
    }
}
